package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.db.mapper.UmsAdminRoleRelationMapper;
import com.mall.pojo.UmsAdminRoleRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UmsAdminRoleRelationApiImpl implements UmsAdminRoleRelationApi {

    @Autowired
    private UmsAdminRoleRelationMapper adminRoleRelationMapper;

    /**
     * 根据当前管理员id查询角色关系
     *
     * @param id
     * @return
     */
    @Override
    public UmsAdminRoleRelation findByAdmin(Long id) {
        LambdaQueryWrapper<UmsAdminRoleRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsAdminRoleRelation::getAdminId, id);
        return adminRoleRelationMapper.selectOne(wrapper);
    }

    @Override
    public Integer add(UmsAdminRoleRelation relation) {
        return adminRoleRelationMapper.insert(relation);
    }

    @Override
    public void delete(Integer adminId) {
        LambdaQueryWrapper<UmsAdminRoleRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsAdminRoleRelation::getAdminId,adminId);
        adminRoleRelationMapper.delete(wrapper);
    }

    @Override
    public UmsAdminRoleRelation find(Integer adminId, Integer roleId) {
        LambdaQueryWrapper<UmsAdminRoleRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsAdminRoleRelation::getAdminId,adminId)
                .eq(UmsAdminRoleRelation::getRoleId,roleId);
        return adminRoleRelationMapper.selectOne(wrapper);
    }

    @Override
    public List<UmsAdminRoleRelation> findByAdminId(Long adminId) {
        LambdaQueryWrapper<UmsAdminRoleRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsAdminRoleRelation::getAdminId,adminId);
        return adminRoleRelationMapper.selectList(wrapper);
    }
}
